<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<script type="text/javascript">
$(function(){
	$(".datepicker").datepicker({dateFormat:'yy-mm-dd', changeMonth:true});
});
</script>
<fieldset><legend>查询条件</legend>
<form method="get" action="">
<?include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table">
<tr>
	<th>店铺/网站</th>
	<td>
		<select name="shop_id">
			<option value="">请选择</option>
			<?foreach ($aliexpress_shop as $as):?>
			<option value="<?=$as['id']?>" <?if (isset($_GET['shop_id']) && $as['id'] == $_GET['shop_id'])echo "selected='selected'"?>><?=$as['name']?></option>
			<?endforeach;?>
		</select>
	</td>
	<td></td>
</tr>
<tr>
	<th>销售时间</th>
	<td>
		<input type="text" name="begin_sales_time" class="datepicker" value="<?=isset($_GET['begin_sales_time']) ? $_GET['begin_sales_time'] : '';?>" /> to 
		<input type="text" name="end_sales_time" class="datepicker" value="<?=isset($_GET['end_sales_time']) ? $_GET['end_sales_time'] : '';?>" />
	</td>
	<td></td>
</tr>
<tr>
	<th>发货时间</th>
	<td>
		<input type="text" name="begin_shipped_time" class="datepicker" value="<?=isset($_GET['begin_shipped_time']) ? $_GET['begin_shipped_time'] : '';?>" /> to 
		<input type="text" name="end_shipped_time" class="datepicker" value="<?=isset($_GET['end_shipped_time']) ? $_GET['end_shipped_time'] : '';?>" />
	</td>
	<td></td>
</tr>
<tr>
	<th>放款时间</th>
	<td>
		<input type="text" name="begin_loan_time" class="datepicker" value="<?=isset($_GET['begin_loan_time']) ? $_GET['begin_loan_time'] : '';?>" /> to 
		<input type="text" name="end_loan_time" class="datepicker" value="<?=isset($_GET['end_loan_time']) ? $_GET['end_loan_time'] : '';?>" />
	</td>
	<td></td>
</tr>
<tr>
	<th>放款状态</th>
	<td>
		<? foreach (Q::ini('custom_flag/sales_order_loan_status') as $sols):?>
		<label><input type="checkbox" name="loan_status[<?=$sols['value']?>]" value="<?=$sols['value']?>" <?=isset($_GET['loan_status']) && array_key_exists($sols['value'], $_GET['loan_status']) ? "checked='checked'" : '';?> /> <?=$sols['name']?></label>
		<? endforeach;?>
	</td>
	<td></td>
</tr>
<tr>
	<td colspan="2">
		<input type="hidden" name="is_search" value="1" />
		<input type="submit" class="button" value="查询" />
	</td>
	<td align="right">
		<?if (isset($url_arr)):?>
		<a href="<?=url('Datacenter::Finance/ExportAliExpressLoanInfo', $url_arr)?>"><input type="button" class="button" value="导出列表"/></a>
		<?else:?>
		&nbsp;
		<?endif;?>
	</td>
</tr>	
</table>
</form>
</fieldset>
<?if ( ! empty($sales_order)):?>
<table class="list_table" width="100%">
<tr>
	<th>订单号</th>
	<th>店铺单号</th>
	<th>销售时间</th>
	<th>发货时间</th>
	<th>付款时间</th>
	<th>币种</th>
	<th>汇率</th>
	<th>订单金额</th>
	<th>放款币种</th>
	<th>放款金额</th>
	<th>放款时间</th>
</tr>
<?foreach ($sales_order as $so):?>
<tr>
	<td><?=$so['number']?></td>
	<td><?=$so['shop_order_number']?></td>
	<td><?=$so['sales_time']?></td>
	<td><?=$so['shipped_time']?></td>
	<td><?=$so['paid_time']?></td>
	<td><?=$so['currency_code']?></td>
	<td><?=$so['currency_rate']?></td>
	<td><?=sprintf('%.2f', $so['amount'])?></td>
	<td><?=$so['loan_currency_code']?></td>
	<td><?=isset($so['loan_amount']) ? sprintf('%.2f', $so['loan_amount']) : '';?></td>
	<td><?=$so['loan_time']?></td>
</tr>
<?endforeach;?>
</table>
<?=$page?>
<?endif;?>
<?if (isset($order_amount) && isset($loan_amount)):?>
<?$order = $loan = array();?>
<?$order_amount_cny = 0;?>
<?foreach ($order_amount as $oa):?>
<?$order_amount_cny += $oa['amount_cny']?>
<?$order[] = '<strong>' . $oa['code'] . '：</strong>' . (isset($oa['amount']) ? sprintf('%.2f', $oa['amount']) : '0.00');?>
<?endforeach;?>
<?foreach ($loan_amount as $la):?>
<?$loan[] = '<strong>' . $la['code'] . '：</strong>' . (isset($la['loan_amount']) ? sprintf('%.2f', $la['loan_amount']) : '0.00');?>
<?endforeach;?>
搜索条件订单总额：
<?=implode(' + ', $order) . ' = <strong>CNY：</strong>' . sprintf('%.2f', $order_amount_cny);?><br />
搜索条件放款总额：
<?=implode(' + ', $loan);?>
<?endif;?>
<?php $this->_endblock(); ?>